﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp7
{
    class Program
    {

        static Student s1 = new Student(10086, "张三", 38);
        static Student s2 = new Student(10087, "李四", 20);
        static Student s3 = new Student(10088, "王五", 25);
        static Student s4 = new Student(10089, "李六", 19);
        static Student s5 = new Student(10090, "陈七", 45);
        static List<Student> list = new List<Student>();
        static Hashtable ht = new Hashtable();


        static void Main(string[] args)
        {
            list.Add(s1);
            list.Add(s2);
            list.Add(s3);
            list.Add(s4);
            list.Add(s5);

            ht.Add(s1._stuid, s1);
            ht.Add(s2._stuid, s2);
            ht.Add(s3._stuid, s3);
            ht.Add(s4._stuid, s4);
            ht.Add(s5._stuid, s5);


            Text();
        }

        class NumSort : IComparer<Student>
        {
            public int Compare(Student x, Student y)
            {

                return x._stuid.CompareTo(y._stuid);
            }
        }//学号比较
        class NameSort : IComparer<Student>
        {
            public int Compare(Student x, Student y)
            {

                return x._name.CompareTo(y._name);
            }
        }//姓名比较
        class AgeSort : IComparer<Student>
        {
            public int Compare(Student x, Student y)
            {

                return x._age.CompareTo(y._age);
            }
        }//年龄比较

        class Student : IComparable
        {
            public int _stuid;
            public string _name;
            public int _age;

            public Student(int stuid, string name, int age)
            {
                _stuid = stuid;
                _name = name;
                _age = age;
            }
            public Student()
            {

            }

            public Student(object name, int age)
            {
            }

            public override string ToString()
            {
                return $"我的学号是{_stuid},我叫{_name},我年龄是{_age}";
            }

            public int CompareTo(object obj)
            {
                throw new NotImplementedException();
            }
        }//学生类 


        static void Text()//首页 
        {
            Console.WriteLine("请选择：1、添加学生信息 2、查询学生信息");
            int key = int.Parse(Console.ReadLine());
            switch (key)
            {
                case 1:
                    AddStudent();
                    break;
                case 2:
                    ChaXun();
                    break;
                default:
                    break;
            }
        }

        static void ChaXun()//查询学生信息 
        {
            Console.WriteLine("--------------------------------------------------------------------------");
            Console.WriteLine("1、查询所有（按学号排序）2、查询所有（按姓名排序）6、返回上一级");
            Console.WriteLine("                  ------------------------                 ");
            Console.WriteLine("3、查询所有（按年龄排序）4、按学号查询（查没有，则打印查无此学生）5、退出");
            int key = int.Parse(Console.ReadLine());
            switch (key)
            {
                case 1:
                    list.Sort(new NumSort());
                    list.Reverse();
                    foreach (var s in list)
                    {
                        Console.WriteLine(s);
                    }
                    ChaXun();
                    break;
                case 2:
                    list.Sort(new NameSort());
                    foreach (var s in list)
                    {
                        Console.WriteLine(s);
                    }
                    ChaXun();
                    break;
                case 3:
                    list.Sort(new AgeSort());
                    foreach (var s in list)
                    {
                        Console.WriteLine(s);
                    }
                    ChaXun();
                    break;
                case 4:
                    Console.WriteLine("请输入学号：");
                    int i = int.Parse(Console.ReadLine());
                    if (ht.Contains(i))
                    {
                        Console.WriteLine(ht[i]);
                    }
                    else
                    {
                        Console.WriteLine("该学生不存在!!!");
                    }

                    ChaXun();
                    break;
                case 5:
                    Console.WriteLine("程序结束！！");
                    break;
                case 6:
                    Text();
                    break;
                default:
                    Console.WriteLine("输入有误！请重新输入！！");
                    ChaXun();
                    break;
            }

        }


        static void AddStudent()//添加学生信息
        {
            Console.WriteLine("请输入学号：");
            int stuid = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入姓名：");
            string name = Console.ReadLine();
            Console.WriteLine("请输入年龄");
            int age = int.Parse(Console.ReadLine());
            Student ss = new Student(stuid, name, age);

            if (ht.Contains(stuid))
            {
                Console.WriteLine("该学号已存在！！");
                AddStudent();
            }
            else
            {
                list.Add(ss);
                ht.Add(ss._stuid, ss);
                Text();
            }




        }

    }
}